package src.graph;

import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import src.util.MiniMap;
import src.util.MiniSet;

import checkers.javari.quals.ReadOnly;
import checkers.nullness.quals.NonNull;
import checkers.nullness.quals.Nullable;
import checkers.quals.DefaultLocation;
import checkers.quals.DefaultQualifier;
@DefaultQualifier(value = "checkers.nullness.quals.NonNull", locations =
{ DefaultLocation.ALL_EXCEPT_LOCALS })
public class GraphPrinter {

	public String print(Graph g) {
		StringBuffer sb = new StringBuffer();
		sb.append("nodes: ");
		MiniSet<String> nodes = g.nodes();
		for (String nodeId : nodes) {
			sb.append(nodeId + ",");
		}
		sb.append("\n");
		sb.append("edges: ");
		MiniMap<String,@Nullable MiniSet<String>> edges = g.edges();
		for (String nodeId: nodes) {
			MiniSet<String> image = edges.get(nodeId);
			if (image == null)
				sb.append(nodeId + "->" + "UNIV" + ",");
			else {
				for (String to : image) {
					sb.append(nodeId + "->" + to + ", ");
				}
			}
		}
		sb.append("\n");
		return sb.toString();
	}

}
